#include <common/cmdline/cmdline.h>

using namespace std;

int main(int argc, char *argv[])
{
    cmdline::parser a;
    // add specified type of variable.
    // 1st argument is long name
    // 2nd argument is short name (no short name if '\0' specified)
    // 3rd argument is description
    // 4th argument is mandatory (optional. default is false)
    // 5th argument is default value  (optional. it used when mandatory is false)
    a.add<string>("host", 'h', "host name", true, "");
    // 6th argument is extra constraint.
    // Here, port number must be 1 to 65535 by cmdline::range().
    a.add<int>("port", 'p', "port number", false, 80, cmdline::range(1, 65535));
    // cmdline::oneof() can restrict options.
    a.add<string>("type", 't', "protocol type", false, "http", cmdline::oneof<string>("http", "https", "ssh", "ftp"));
    // Boolean flags also can be defined.
    // Call add method without a type parameter.
    a.add("gzip", '\0', "gzip when transfer");

    // Run parser.
    // It returns only if command line arguments are valid.
    // If arguments are invalid, a parser output error msgs then exit program.
    // If help flag ('--help' or '-?') is specified, a parser output usage message then exit program.
    a.parse_check(argc, argv);

    cout << a.get<string>("type") << "://"
         << a.get<string>("host") << ":"
         << a.get<int>("port") << endl;

    if (a.exist("gzip")) cout << "gzip" << endl;

    return 0;
}
